import 'package:flutter/material.dart';
import 'package:flutter_buisiness_2006a/bean/category_goods_list_bean_result.dart';
import 'package:flutter_buisiness_2006a/provider/detail_info_provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:provider/provider.dart';

class DetailTop extends StatelessWidget {
  const DetailTop({Key? key}) : super(key: key);

  //商品头部的banner
  Widget _goodsBanner(CategoryGoodsListBean? goodsInfo) {
    return SizedBox(
      height: ScreenUtil().setHeight(700).toDouble(),
      child: Swiper(
        itemCount: goodsInfo!.bannerList!.length,
        itemBuilder: (context, index) {
          return Image.network(
            goodsInfo.bannerList![index]!,
            fit: BoxFit.fill,
          );
        },
        pagination: const SwiperPagination(),
        autoplay: true,
      ),
    );
  }

  //商品名称
  Widget _goodsName(CategoryGoodsListBean? goodsInfo) {
    return Container(
      width: ScreenUtil().setWidth(730).toDouble(),
      padding: const EdgeInsets.only(left: 15, right: 15),
      child: Text(
        goodsInfo!.goods_desc!,
        maxLines: 3,
        style: TextStyle(fontSize: ScreenUtil().setSp(30).toDouble()),
      ),
    );
  }

  //商品编号
  Widget _goodsNum(CategoryGoodsListBean? goodsInfo) {
    return Container(
      width: ScreenUtil().setWidth(730).toDouble(),
      padding: const EdgeInsets.only(left: 15),
      child: Text(
        '编号:${goodsInfo!.goods_code}',
        style: const TextStyle(color: Colors.black26),
      ),
    );
  }

  //商品价格
  Widget _goodsPrice(CategoryGoodsListBean? goodsInfo) {
    return Container(
      padding: const EdgeInsets.only(left: 15, right: 15),
      margin: const EdgeInsets.only(top: 8),
      child: Row(
        children: [
          Text(
            '团购价:￥${goodsInfo!.goods_default_price}元',
            style: TextStyle(
                fontSize: ScreenUtil().setSp(40).toDouble(),
                color: Colors.pink),
          ),
          Text(
            '原价:￥${goodsInfo.goods_default_price}元',
            style: const TextStyle(
                color: Colors.black26, decoration: TextDecoration.lineThrough),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    CategoryGoodsListBean? goodsInfo =
        Provider.of<DetailInfoProvider>(context).goodsInfo;
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.all(2),
      child: Column(
        children: [
          _goodsBanner(goodsInfo),
          _goodsName(goodsInfo),
          _goodsNum(goodsInfo),
          _goodsPrice(goodsInfo),
        ],
      ),
    );
  }
}
